import 'dart:io';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:du_application/provide/AffairProvider.dart';
import 'package:du_application/routes/application.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';

class Affairs extends StatelessWidget {
  const Affairs({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Provide<AffairProvider>(builder: (context, child, index){
    return Scaffold(
    body:Container(
      padding: EdgeInsets.symmetric(horizontal:ScreenUtil().setWidth(10)),
          color:Colors.white,
            child: Column(
              children: <Widget>[
                Container(
              margin: EdgeInsets.only(top:ScreenUtil().setHeight(40)),
              color:Colors.white,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                 Container(
                   margin: EdgeInsets.only(top:ScreenUtil().setHeight(20)),
                   child: FlatButton(
                     onPressed: () {
                       index.record();
                       Navigator.of(context).popUntil(ModalRoute.withName('/person'));
                     },
                     child: Text("取消"),
                   )
                 ),
                  FlatButton(
                    onPressed: () async {
                      EasyLoading.show();
                     bool result= await index.addTopic(context);
                    if(result){
                     index.record();
                     EasyLoading.dismiss();
                      Navigator.of(context).popUntil(ModalRoute.withName('/person'));
                    }
                    },
                    child:  Container(
                         padding: EdgeInsets.symmetric(
                        horizontal: ScreenUtil().setWidth(40),
                        vertical: ScreenUtil().setWidth(10)),
                      color:Colors.cyan[400],
                      child: Text("发布", style: TextStyle(color: Colors.white))
                    ),
                  )
                ],
              )
            ),
               Container(
                 constraints: BoxConstraints(
                  minHeight:ScreenUtil().setHeight(200)
                 ),
                 decoration: BoxDecoration(
                  
                 border:Border.all(width:ScreenUtil().setSp(1),color:Colors.grey)
                 ),
                 padding: EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(10)),
                 child: TextField(
                     onChanged: (value){
                       index.setContent(value);
                     },
                     maxLengthEnforced: false, maxLines: null,
                   decoration: InputDecoration(
                    border: InputBorder.none,
                     hintText:"分享你的热爱"
                   ),
               ),
              
                ),
               Container(
                 
                 margin: EdgeInsets.only(top: ScreenUtil().setHeight(40)),
                 width: ScreenUtil().setWidth(460),
                 height: ScreenUtil().setWidth(460),
                 child: CachedNetworkImage( imageUrl:index.url,
                           fit:BoxFit.fitWidth,
                           placeholder: (context, url) =>
                               Image.asset('assets/loading.jpg',fit:BoxFit.fitWidth,),
                          )
               ),
               InkWell(
                 onTap: (){
                   Application.router.pop(context);
                 },
                 child: Container(
                   
                  decoration: BoxDecoration(
                    // color:Color.fromRGBO(0,0,0,0.5),
                   border:Border.all(width:ScreenUtil().setSp(1),color:Colors.grey),
                     borderRadius: BorderRadius.circular(8.0),
                      boxShadow: [
                        BoxShadow(
                            color: Colors.black,
                            offset: Offset(0.0, ScreenUtil().setSp(15)), //阴影xy轴偏移量
                            blurRadius: ScreenUtil().setSp(15), //阴影模糊程度
                            spreadRadius: ScreenUtil().setSp(2) //阴影扩散程度
                            )
                      ]),
               
              
                 padding: EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(10),vertical: ScreenUtil().setWidth(5) ),
                  margin: EdgeInsets.only(top: ScreenUtil().setHeight(40)),
                              
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children:[
                                     Container(
                       
                                       alignment: Alignment.topLeft,
                                       child: Text("@我的单品",style: TextStyle(color:Colors.grey),),
                                     ),
                                     Row(
                                       crossAxisAlignment: CrossAxisAlignment.start,
                                       mainAxisAlignment: MainAxisAlignment.start,
                                       children:[
                                     Container(
                                     
                                     width: ScreenUtil().setWidth(200),
                                     height: ScreenUtil().setWidth(200),
                                     child: CachedNetworkImage(imageUrl:index.tips.goods.picUrl,
                                     fit: BoxFit.fill,
                                     placeholder: (context, url) =>
                                                                 Image.asset('assets/loading.jpg',),
                                       )
                                   ),
                                   Container(
                                       padding: EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(10) ),
                                     alignment: Alignment.topLeft,
                                     width: ScreenUtil().setWidth(820),
                                   child:Text(index.tips.goods.name,style:TextStyle(
                                   color:  Colors.white70
                                   )),
                                   )
                                       ]
                                     )

                                  ]
                                )
                              )
               ),
              //    GridView.count(
              //   children: <Widget>[
                  
              //   ],
              //   crossAxisCount: 3,
                 
              //  )
              ],
            ),  
  ) 
       
    );


    });
 
  }
}
